<?php

namespace common\traits\relation;

use Yii;

/**
 * 类静态常量定义解析特性方法
 *
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
trait Tree {

    /**
     * 节点父级分类
     */
    public function getParent() {
        return $this->hasOne(static::className(), ['id' => 'parent_id']);
    }

    /**
     * 节点子级分类
     */
    public function getChildren() {
        return $this->hasMany(static::className(), ['parent_id' => 'id']);
    }

    /**
     * 节点出度
     */
    public function getDegrees() {
        return $this->getChildren()->count();
    }

}
